/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 26727
 * Date: 2025-06-02
 * Time: 10:28
 */
public class ShellSort {
    public static void main(String[] args) {
        int[] array = {1,4,2,9,6,7};
        int gap = array.length;
        while(gap > 1) {
            shellSort(array,gap);
            gap /= 2;
        }
        shellSort(array,1);
        for(int i = 0; i < array.length; i++) {
            System.out.print(array[i]+" ");
        }
    }

    public static void shellSort(int[] array,int gap) {
        for(int i = gap; i < array.length; i++) {
            int tmp = array[i];
            int j = i-gap;
            for(; j >= 0; j-=gap) {
                if(array[j] > tmp) {
                    array[j+gap] = array[j];
                }else {
                    //array[j+1] = tmp;
                    break;
                }
            }
            array[j+gap] = tmp;
        }
    }
}
